package com.ruoyi.patrol.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.patrol.vo.PtEquipmentVO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.patrol.domain.PtEquipment;
import com.ruoyi.patrol.service.IPtEquipmentService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 设备信息Controller
 *
 * @author linan
 * @date 2024-02-03
 */
@RestController
@RequestMapping("/resource/equipment")
public class PtEquipmentController extends BaseController
{
    @Autowired
    private IPtEquipmentService ptEquipmentService;

    /**
     * 查询设备信息列表
     */
    @PreAuthorize("@ss.hasPermi('resource:equipment:list')")
    @GetMapping("/list")
    public TableDataInfo list(PtEquipment ptEquipment)
    {
        startPage();
        List<PtEquipmentVO> list = ptEquipmentService.selectPtEquipmentList(ptEquipment);
        return getDataTable(list);
    }

    /**
     * 导出设备信息列表
     */
    @PreAuthorize("@ss.hasPermi('resource:equipment:export')")
    @Log(title = "设备信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PtEquipment ptEquipment)
    {
        List<PtEquipmentVO> list = ptEquipmentService.selectPtEquipmentList(ptEquipment);
        ExcelUtil<PtEquipmentVO> util = new ExcelUtil<>(PtEquipmentVO.class);
        util.exportExcel(response, list, "设备信息数据");
    }

    /**
     * 获取设备信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('resource:equipment:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(ptEquipmentService.selectPtEquipmentById(id));
    }

    /**
     * 新增设备信息
     */
    @PreAuthorize("@ss.hasPermi('resource:equipment:add')")
    @Log(title = "设备信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PtEquipment ptEquipment)
    {
        return toAjax(ptEquipmentService.insertPtEquipment(ptEquipment));
    }

    /**
     * 修改设备信息
     */
    @PreAuthorize("@ss.hasPermi('resource:equipment:edit')")
    @Log(title = "设备信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PtEquipment ptEquipment)
    {
        return toAjax(ptEquipmentService.updatePtEquipment(ptEquipment));
    }

    /**
     * 删除设备信息
     */
    @PreAuthorize("@ss.hasPermi('resource:equipment:remove')")
    @Log(title = "设备信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ptEquipmentService.deletePtEquipmentByIds(ids));
    }
}
